package cn.stylefeng.guns.modular.ry600.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.stylefeng.guns.core.util.CacheUtil;
import cn.stylefeng.guns.core.util.Token;
import cn.stylefeng.guns.modular.system.model.Check;
import cn.stylefeng.guns.modular.system.model.ClientCheck;
import cn.stylefeng.guns.modular.system.dao.CheckMapper;
import cn.stylefeng.guns.modular.ry600.service.ICheckService;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author stylefeng
 * @since 2019-01-02
 */
@Service
public class CheckServiceImpl extends ServiceImpl<CheckMapper, Check> implements ICheckService {

	@Override
	public Map<String,Object> checkToken(ClientCheck clientCheck) {
		Map<String,Object> search=new HashMap<String,Object>();
		search.put("client_id",clientCheck.getClient_id());
		List<Check> checkList= this.selectList(null);
		if(checkList.size()>0){
			for(int i=0;i<checkList.size();i++){
				if(clientCheck.getClient_secret().equals(checkList.get(i).getCheckSecret())&&clientCheck.getClient_id().equals(checkList.get(i).getCheckId())){
					//生成token
					String token=Token.getToken(clientCheck.getClient_id());
					//缓存token
//					CacheUtil.put(clientCheck.getClient_id(), clientCheck.getClient_id(), token);
					CacheUtil.put("bearer "+token,"bearer "+token,"bearer "+token);
					System.out.println("项目验证通过");
					Map<String,Object> resultToken=new HashMap<String,Object>();
					resultToken.put("access_token", token);
					resultToken.put("expires_in", 3600);
					return resultToken;
				}
			}
		}
		//System.out.println(CacheUtil.get(clientCheck.getClient_id(), clientCheck.getClient_id()));
		System.out.println("客户不存在");
		return null;
	}

}
